package com.akk.module.yb.model;

import com.akk.PayConstants;
import com.akk.module.yb.utils.Digest;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

import java.util.ArrayList;
import java.util.List;

public class WithdrawQueryRequest {
    private String mainCustomerNumber;
    private String customerNumber;
    private String externalNo;
    private String serialNo;
    private String requestDateSectionBegin;
    private String requestDateSectionEnd;
    private String transferStatus;
    private String transferWay;
    private String pageNo;
    private String hmac;

    public String getMainCustomerNumber() {
        return mainCustomerNumber;
    }

    public void setMainCustomerNumber(String mainCustomerNumber) {
        this.mainCustomerNumber = mainCustomerNumber;
    }

    public String getCustomerNumber() {
        return customerNumber;
    }

    public void setCustomerNumber(String customerNumber) {
        this.customerNumber = customerNumber;
    }

    public String getExternalNo() {
        return externalNo;
    }

    public void setExternalNo(String externalNo) {
        this.externalNo = externalNo;
    }

    public String getRequestDateSectionBegin() {
        return requestDateSectionBegin;
    }

    public void setRequestDateSectionBegin(String requestDateSectionBegin) {
        this.requestDateSectionBegin = requestDateSectionBegin;
    }

    public String getRequestDateSectionEnd() {
        return requestDateSectionEnd;
    }

    public void setRequestDateSectionEnd(String requestDateSectionEnd) {
        this.requestDateSectionEnd = requestDateSectionEnd;
    }

    public String getTransferStatus() {
        return transferStatus;
    }

    public void setTransferStatus(String transferStatus) {
        this.transferStatus = transferStatus;
    }

    public String getTransferWay() {
        return transferWay;
    }

    public void setTransferWay(String transferWay) {
        this.transferWay = transferWay;
    }

    public String getPageNo() {
        return pageNo;
    }

    public void setPageNo(String pageNo) {
        this.pageNo = pageNo;
    }

    public String getHmac() {
        return hmac;
    }

    public void setHmac(String hmac) {
        this.hmac = hmac;
    }

    public static String signature(WithdrawQueryRequest request) {
        StringBuffer sb = new StringBuffer();
        sb.append(request.getCustomerNumber() == null? "":request.getCustomerNumber());
        sb.append(request.getExternalNo() == null?"":request.getExternalNo());
        sb.append(request.getMainCustomerNumber()==null?"":request.getMainCustomerNumber());
        sb.append(request.getPageNo() == null?"":request.getPageNo());
        sb.append(request.getRequestDateSectionBegin() == null?"":request.getRequestDateSectionBegin());
        sb.append(request.getRequestDateSectionEnd() == null?"":request.getRequestDateSectionEnd());
        sb.append(request.getSerialNo() == null?"":request.getSerialNo());
        sb.append(request.getTransferStatus() == null?"":request.getTransferStatus());
        sb.append(request.getTransferWay() == null?"":request.getTransferWay());
        return Digest.hmacSign(sb.toString(), PayConstants.YB_PARAMS_HMAC_KEY);
    }

    public static Part[] builderPart(WithdrawQueryRequest request) {
        List<Part> parts = new ArrayList<Part>();
        parts.add(new StringPart("mainCustomerNumber",request.getMainCustomerNumber()==null?"":request.getMainCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("customerNumber",request.getCustomerNumber() == null?"":request.getCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("externalNo",request.getExternalNo() == null?"":request.getExternalNo(),"UTF-8"));
        parts.add(new StringPart("serialNo",request.getSerialNo() == null?"":request.getSerialNo(),"UTF-8"));
        parts.add(new StringPart("requestDateSectionBegin",request.getRequestDateSectionBegin() == null?"":request.getRequestDateSectionBegin(),"UTF-8"));
        parts.add(new StringPart("requestDateSectionEnd",request.getRequestDateSectionEnd() == null?"":request.getRequestDateSectionEnd(),"UTF-8"));
        parts.add(new StringPart("transferStatus",request.getTransferStatus() == null?"":request.getTransferStatus(),"UTF-8"));
        parts.add(new StringPart("transferWay",request.getTransferWay() == null?"":request.getTransferWay(),"UTF-8"));
        parts.add(new StringPart("pageNo",request.getPageNo() == null?"":request.getPageNo(),"UTF-8"));
        parts.add(new StringPart("hmac",request.getHmac()== null?"":request.getHmac(),"UTF_8"));
        return parts.toArray(new Part[parts.size()]);
    }

    public String getSerialNo() {
        return serialNo;
    }

    public void setSerialNo(String serialNo) {
        this.serialNo = serialNo;
    }
}
